﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BCS.Business;
using BCS.Model;

namespace BCS.WinFormAppGui
{
        public partial class TeamForm : Form
        {
                private BusinessCache cache = BusinessCache.Instance;

                public TeamForm()
                {
                        InitializeComponent();
                }

                private void Form_Load(object sender, EventArgs e)
                {
                        TeamComboBox.Items.Add("甲班");
                        TeamComboBox.Items.Add("乙班");
                        TeamComboBox.Items.Add("丙班");

                        if (cache.CurrentTeam == null)
                        {
                                TeamComboBox.SelectedIndex = 0;
                        }
                        else
                        {
                                TeamComboBox.SelectedItem = cache.CurrentTeam.Name;
                        }
                }

                private void YesButton_Click(object sender, EventArgs e)
                {
                        if (cache.CurrentTeam != null)
                        {
                                cache.CurrentTeam.EndTime = DateTime.Now;
                        }

                        TeamModel model = new TeamModel()
                        {
                                StartTime = DateTime.Now,
                                Name = TeamComboBox.SelectedItem.ToString(),
                                EndTime = DateTime.Now + TimeSpan.FromDays(20)
                        };

                        Team team = new Team(model);

                        cache.InsertTeam(team);
                        cache.CurrentTeam = team;
                        cache.CurrentTeamCount = 0;

                        cache.Save();

                        Close();
                }
        }
}
